vim.g.mapleader = " "

-- NeoTree
vim.keymap.set('n', '<leader>e', ':Neotree float reveal toggle<CR>')
vim.keymap.set('n', '<leader>E', ':Neotree left reveal toggle<CR>')
vim.keymap.set('n', '<leader>o', ':Neotree float git_status toggle<CR>')

-- Navigation
vim.keymap.set('n', '<c-k>', ':wincmd k<CR>')
vim.keymap.set('n', '<c-j>', ':wincmd j<CR>')
vim.keymap.set('n', '<c-h>', ':wincmd h<CR>')
vim.keymap.set('n', '<c-l>', ':wincmd l<CR>')
vim.keymap.set('n', '<c-/>', ':CommentToggle<CR>')
vim.keymap.set('n', '<c-z>', ':undo<CR>')
vim.keymap.set('n', '<s-z>', ':redo<CR>')

-- Splits
-- vim.keymap.set('n', '|', ':vsplit<CR>')
-- vim.keymap.set('n', '\\', ':split<CR>')

-- Other
vim.keymap.set('n', '<leader>w', ':w!<CR>')
vim.keymap.set('n', '<leader>x', ':BufferLinePickClose<CR>')
vim.keymap.set('n', '<leader>X', ':BufferLineCloseRight<CR>')
vim.keymap.set('n', '<leader>s', ':BufferLineSortByTabs<CR>')
vim.keymap.set('i', 'jj', '<Esc>')
vim.keymap.set('n', '<leader>h', ':nohlsearch<CR>')
vim.keymap.set('n', '<leader>q', ':q<CR>')

-- Relative Line toggle
vim.keymap.set('n', '<leader>zr', '<cmd> let [&rnu] = [&nu+&rnu==1]<cr>',
               {desc = 'Relative number toggle'})

-- GIT
vim.keymap.set('n', '<leader>gc', ':G commit<CR>', {desc = 'Commit'})
vim.keymap.set('n', '<leader>gb', ':G blame<CR>', {desc = 'Blame'})
vim.keymap.set('n', '<leader>gd', ':G difftool<CR>', {desc = 'Diff tool'})
vim.keymap.set('n', '<leader>gm', ':G mergetool<CR>', {desc = 'Merge tool'})
vim.keymap.set('n', '<leader>gg', ':G<CR>', {desc = 'Git main tool'})

-- Tabs
vim.keymap.set('n', '<Tab>', ':BufferLineCycleNext<CR>')
vim.keymap.set('n', '<s-Tab>', ':BufferLineCyclePrev<CR>')
vim.keymap.set('n', '<leader>bp', ':BufferLineTogglePin<CR>')
vim.keymap.set('n', '<a-1>',
               '<cmd>lua require("bufferline").go_to_buffer(1, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-2>',
               '<cmd>lua require("bufferline").go_to_buffer(2, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-3>',
               '<cmd>lua require("bufferline").go_to_buffer(3, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-4>',
               '<cmd>lua require("bufferline").go_to_buffer(4, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-5>',
               '<cmd>lua require("bufferline").go_to_buffer(5, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-6>',
               '<cmd>lua require("bufferline").go_to_buffer(6, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-7>',
               '<cmd>lua require("bufferline").go_to_buffer(7, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-8>',
               '<cmd>lua require("bufferline").go_to_buffer(8, true)<cr>',
               {silent = true})
vim.keymap.set('n', '<a-9>',
               '<cmd>lua require("bufferline").go_to_buffer(9, true)<cr>',
               {silent = true})

-- Terminal
vim.keymap.set('n', '<leader>t', ':ToggleTerm direction=float<CR>')
vim.keymap.set('n', '<leader>th', ':ToggleTerm direction=horizontal<CR>')
